package com.you.atlas.web.member.module.screen;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.member.service.AccountBindService;
import com.you.atlas.biz.member.service.FollowQueryService;
import com.you.atlas.biz.place.service.AlbumQueryService;
import com.you.atlas.biz.place.service.NoteQueryService;
import com.you.common.ibatis.data.DataList;
import com.you.common.webx.AuthContext;
import com.you.member.biz.service.MemberQueryService;
import com.you.member.dal.dao.dataobject.AccountBindDO;
import com.you.member.dal.dao.dataobject.MemberDO;

public class Home {

    @Autowired
    private MemberQueryService memberQueryService;

    @Autowired
    private NoteQueryService   noteQueryService;

    @Autowired
    private AlbumQueryService  albumQueryService;

    @Autowired
    private FollowQueryService followQueryService;
    
    @Autowired
    private AccountBindService accountBindService;

    public void execute(@Param("id") Long memberId, Context context, Navigator navigator) {
        if (memberId == null) {
            memberId = AuthContext.getContext().getMemberId();
            navigator.redirectTo("memberModule").withTarget("home").uri().addQueryData("memberId", memberId);
            return;
        }
        MemberDO memberDO = memberQueryService.find(memberId);
        if (memberDO != null) {
            DataList noteDataList = noteQueryService.queryNoteBymemberId(0, memberId);
            DataList photoDataList = albumQueryService.queryAlbumByMemberId(0, 5, memberId);
            context.put("memberDO", memberDO);
            context.put("noteDataList", noteDataList);
            context.put("photoDataList", photoDataList);
            context.put("fans", followQueryService.countFans(memberId));
            context.put("follow", followQueryService.countFollow(memberId));
            context.put("isFollow", followQueryService.isFollow(memberId, AuthContext.getContext().getMemberId()));
            AccountBindDO  accountBind = accountBindService.findByMemberId(memberId);
            context.put("accountBind", accountBind);
        } else {
            navigator.redirectTo("memberModule").withTarget("error.vm");
        }

    }
}
